﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DAL;
public partial class BaseInfoMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //判断用户是否已经登录
        try
        {
            if (!CMSUser.Current.IsLogin)
            {
                Response.Redirect("~/Login.aspx");
            }
        }
        catch (Exception)
        {
            Response.Redirect("~/Login.aspx");
        }

        NavDataBind();
        lab_Time.Text = "当前系统时间：" + DateTime.Now;
        lab_User.Text = "欢迎您！" + CMSUser.Current.Name + "！";
    }

    //显示类型
    private void NavDataBind()
    {
        this.ASPxNavType.Groups.Clear();
        this.ASPxNavType.Font.Size = FontUnit.Parse("10pt");
        if (Cache["NavDatalist"] == null)        //获取或设置指定键外的缓存项
        {
            using (DAL.DataClassesDataContext lqDB = new DataClassesDataContext())
            {
                Cache["NavDatalist"] = lqDB.Functions.ToList();
            }
        }

        //先获取数据
        List<DAL.Functions> AllList = Cache["NavDatalist"] as List<DAL.Functions>;          //所有内容
        List<DAL.Functions> groupList = AllList.Where(o => o.ParentID == "0").ToList();     //一级节点
        foreach (DAL.Functions group in groupList)
        {
            DevExpress.Web.ASPxNavBar.NavBarGroup NvGroup = this.ASPxNavType.Groups.Add(group.Description, group.FunctionID);   //显示内容
            List<DAL.Functions> itemlist = AllList.Where(o => o.ParentID == group.FunctionID).ToList();   //列出对应的二级内容
            foreach (DAL.Functions item in itemlist)
            {
                //判断是否拥有操作权限
                if (CMSUser.Current.CheckActionAllow(item.FunctionID))
                {
                    NvGroup.Items.Add(item.Description, item.FunctionID, string.Empty, item.Url);
                }
            }
        }
    }
}
